import 'package:flutter/material.dart';
import 'package:flutter_dk_form/flutter_dk_form.dart';

/// 单行输入
class DkDropDownFormField extends DkFormField<DkDropDownItem> {
  DkDropDownFormField({
    Key key,
    @required String attribute,
    String title = '',
    String placeholder = '',
    DkDropDownItem initialValue,
    ValueChanged<DkDropDownItem> onChanged,
    DkFormFieldValidator<DkDropDownItem> validator,
    ValueTransformer valueTransformer,
    List<DkDropDownItem> list,
    bool hasLine = true,
  }) : super(
          attribute: attribute,
          initialValue: initialValue,
          validator: validator,
          valueTransformer: (value){
            if(valueTransformer!=null){
              return valueTransformer(value);
            }else{
              return value!=null?value.value:null;
            }
          },
          builder: (DkFormFieldState<DkDropDownItem> field) {
            final DkFormFieldState state = field;
            void onChangedHandler(DkDropDownItem value) {
              if (onChanged != null) {
                onChanged(value);
              }
              field.didChange(value);
            }

            return DropDownWidget(
              title: title,
              placeHolder: placeholder,
              items: list,
              hasLine: hasLine,
              onChanged: onChangedHandler,
            );
          },
        );
}
